package cn.xorange.commons.system.service.System.impl;

import cn.xorange.commons.core.basic.service.BaseService;
import cn.xorange.commons.security.utils.SecurityUtils;
import cn.xorange.commons.system.entity.system.SysTenantMenu;
import cn.xorange.commons.system.mapper.system.SysTenantMenuMapper;
import cn.xorange.commons.system.service.System.ISysTenantMenuService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author : yangjian
 * date : 2024/10/29
 * description :
 */
@Service
public class SysTenantMenuServiceImpl extends BaseService<SysTenantMenu, SysTenantMenuMapper> implements ISysTenantMenuService {

    @Override
    public List<SysTenantMenu> getList(SysTenantMenu menu){
        Long tenantId = SecurityUtils.getTenantId();
        menu.setTenantId(tenantId);
        return mapper.selectList(menu);
    }

    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public int update(SysTenantMenu menu) {
        menu.setTenantId(SecurityUtils.getTenantId());
        SysTenantMenu m = new SysTenantMenu();
        m.setTenantId(menu.getTenantId());
        m.setMenuId(menu.getMenuId());
        int check = super.count(m);
        if (check > 0) {
            menu.where.equal("menuId", menu.getMenuId());
            return mapper.update(menu);
        } else {
            return mapper.insert(menu);
        }
    }
}
